home *** CD-ROM | disk | FTP | other *** search
- #include <ctype.h>
- #include <curses.h>
- #include <signal.h>
- #include <stdio.h>
- #include <term.h>
-
- extern void exit();
- extern void perror();
-
- #define PROMPT "*** Page Pause, press RETURN to continue, Q to quit: "
- #define TTYFILE "/dev/tty"
-
- /*---------------------------------------------------------------------------*/
-
- static int done()
- {
- resetterm();
- exit(0);
- }
-
- /*---------------------------------------------------------------------------*/
-
- main(argc, argv)
- int argc;
- char **argv;
- {
-
- FILE * fi = (FILE * ) 0;
- FILE * fp = stdin;
- char buf1[1024], buf2[1024];
- int line = 0;
- int col = 0;
-
- int line_not_empty = 0;
- int maxline;
-
- int extmaxlines = 22;
- int extmaxcols = 255;
- int i;
-
- register char *p, *q;
- register int c;
-
- if (isatty(1) && !(fi = fopen(TTYFILE, "r")))
- {
- perror(TTYFILE);
- exit(1);
- }
-
- if (argc >= 2 && !(fp = fopen(argv[1], "r")))
- {
- perror(argv[1]);
- exit(1);
- }
-
- if (argc > 2)
- {
- extmaxlines = atoi(argv[2]);
- }
-
- if (argc > 3)
- {
- extmaxcols = atoi(argv[3]);
- }
-
- setupterm(0, 1, 0);
- signal(SIGINT, done);
- signal(SIGQUIT, done);
- signal(SIGTERM, done);
- if ((maxline = lines - 2) < 1) maxline = extmaxlines;
- while (fgets(buf1, sizeof(buf1), fp))
- {
- if (fi && line >= maxline)
- {
- printf("%s%s%s", enter_standout_mode, PROMPT, exit_standout_mode);
- if (!fgets(buf2, sizeof(buf2), fi) || *buf2 == 'q' || *buf2 == 'Q') done();
- line = 0;
- }
-
- /***** remove backspaces *****/
-
- for (p = q = buf1; c = *p++ = *q++; )
- if (c == '\b' && (p -= 2) < buf1) p = buf1;
-
- /***** remove trailing white space *****/
-
- for (p = buf1; *p; p++) ;
- while (--p >= buf1 && isspace(*p & 0xff)) ;
- p[1] = '\0';
-
- /***** expand all tabs *****/
-
- for (p = buf1, q = buf2; *p; )
- if (*p == '\t')
- {
- do
- *q++ = ' ';
- while ((q - buf2) & 7);
- p++;
- }
- else
- *q++ = *p++;
- *q = '\0';
-
- /***** output line *****/
-
- if (*buf2 || line_not_empty)
- {
- col = 0;
- i = 0;
- while (buf2[col] != '\0')
- {
- i++;
- putchar(buf2[col]);
- col++;
- if (i >= extmaxcols)
- {
- i = 0;
- line++;
- putchar('\n');
- }
- }
- line++;
- putchar('\n');
- }
- line_not_empty = *buf2;
- }
- done();
- return 0;
- }
-
-